package uitest
{
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.utils.setTimeout;
	import iscript.uiFramework.components.button.BaseButton;
	import iscript.uiFramework.components.container.Box;
	import iscript.uiFramework.components.container.Container;
	import iscript.uiFramework.components.layout.BoxLayout;
	import iscript.uiFramework.components.layout.FlowLayout;
	import iscript.uiFramework.components.layout.HBoxLayout;
	import iscript.uiFramework.components.layout.LayoutAlign;
	import iscript.uiFramework.components.layout.LayoutMargin;
	import iscript.uiFramework.components.panel.ScrollPanel;
	import iscript.uiFramework.util.LineSegment;
	
	public class TLayout extends Sprite
	{
		public function TLayout()
		{
			//test1();
			//testHBoxLayout();
			//testFlowLayout();
			//testBoxLayout();
			textScrollPanel()
		}
		
		private function testHBoxLayout():void {
			var container:Container = new Container(400,300);
			//var container:Box = new Box();
			container.setLayout(new FlowLayout());
			//container.setLayout(new HBoxLayout());
			 for (var i:int = 0; i < 15; i++)
				{
					var ball:Balls = new Balls()		 
					ball.border = true;
					container.append(ball);
					 
				}
			container.border=true
			container.render(this);
			
			setTimeout(function():void {  
			container.getLayout().updateAlign(LayoutAlign.VAlign_CENTER,LayoutAlign.HAlign_RIGHT);
				// hboxLayout.updateAlign(LayoutAlign.VAlign_CENTER,LayoutAlign.HAlign_CENTER);
			},2000)
			
			setTimeout(function():void {
					container.width = 600;
					container.height = 400;
					container.getLayout().hAlign = LayoutAlign.HAlign_RIGHT;
					container.getLayout().vAlign = LayoutAlign.VAlign_BOTTOM;				 
				//	container.getLayout().offY = -50;
				
				trace("container.height",container.height )
				  
			},4000)
			
			 
			 var line:LineSegment = new LineSegment();
				line.thickness = 1
				line.drawRectangle(this.graphics, new Rectangle( container.getLayout().margin.left, container.getLayout().margin.top,
				container.width - container.getLayout().margin.left - container.getLayout().margin.right,  
				container.height - container.getLayout().margin.top-container.getLayout().margin.bottom));
			
			
		}	
		
		
		private function textScrollPanel():void { 
				  var scrollPanel:ScrollPanel = new ScrollPanel();	
				  	  scrollPanel.width = 300;
					  scrollPanel.height = 300
				   scrollPanel.scrollDrag=true;
			               
			      var container:Container = new Container(600,300);
					container.setLayout(new FlowLayout()); 
					 for (var i:int = 0; i < 35; i++)
						{
							var ball:Balls = new Balls()		 
							ball.border = true;
							container.append(ball);
							 
						}
					container.border = true
					scrollPanel.source = container;
					scrollPanel.render(this);
					
					
				 for (i= 0; i < 35; i++)
						{
							var ball:Balls = new Balls()		 
							ball.border = true;
							container.append(ball);
							 
						}	
					scrollPanel.sourceUpdate()
				
				setTimeout(function():void {  
			 //	container.getLayout().updateAlign(LayoutAlign.VAlign_CENTER,LayoutAlign.HAlign_RIGHT);
					// hboxLayout.updateAlign(LayoutAlign.VAlign_CENTER,LayoutAlign.HAlign_CENTER);
				},2000)
			
			
			}
		
		
		private function testFlowLayout():void {
			var container:Container = new Container(400,300);
			//var container:Box = new Box();
			container.setLayout(new FlowLayout()); 
			 for (var i:int = 0; i < 15; i++)
				{
					var ball:Balls = new Balls()		 
					ball.border = true;
					container.append(ball);
					 
				}
			container.border=true
			container.render(this);
			
			setTimeout(function():void {  
			container.getLayout().updateAlign(LayoutAlign.VAlign_CENTER,LayoutAlign.HAlign_RIGHT);
				// hboxLayout.updateAlign(LayoutAlign.VAlign_CENTER,LayoutAlign.HAlign_CENTER);
			},2000)
			
			setTimeout(function():void {
					container.width = 600;
					container.height = 400;
					container.getLayout().hAlign = LayoutAlign.HAlign_RIGHT;
					container.getLayout().vAlign = LayoutAlign.VAlign_BOTTOM;				 
				//	container.getLayout().offY = -50;
				
				trace("container.height",container.height )
				  
			},4000)
			
			 
			 var line:LineSegment = new LineSegment();
				line.thickness = 1
				line.drawRectangle(this.graphics, new Rectangle( container.getLayout().margin.left, container.getLayout().margin.top,
				container.width - container.getLayout().margin.left - container.getLayout().margin.right,  
				container.height - container.getLayout().margin.top-container.getLayout().margin.bottom));
			}
		
		private function testBoxLayout():void {
			   var container:Container = new Container(400,200);
				  
				   
			   var boxLayout:BoxLayout = new BoxLayout();
			  // boxLayout.axis = LayoutAlign.Y_AXIS
			   boxLayout.axis = LayoutAlign.X_AXIS 
			  // boxLayout.hgap = 0;
				//boxLayout.vgap = 20
			   container.setLayout(boxLayout);

			   for (var i:int = 0; i < 2; i++)
				{
					var button:BaseButton = new BaseButton()
					    button.border = true;
					container.getLayout().append(button);
					
				}
				container.border = true;
			   container.render(this);
			   
			
				//setTimeout(function():void{boxLayout.vgap = -15},1000)
			}
		
		
		private function test1():void{		
			var panel:ScrollPanel = new ScrollPanel();
			
			var box:Container = new Container();
		 
			//var  box:Box = new Box();
			//box.scrollDrag = true;
			box.width = 500;
			box.height = 300;
			
			var flowlayout:FlowLayout = new FlowLayout()
			//flowlayout.offX = -10
			box.setLayout(flowlayout)
			
			//var layout:FlowLayout = new FlowLayout(box)
			//var layout:BoxLayout = new BoxLayout(box,"y_axis",0,0)

			var target:Balls;
			for (var i:int = 0; i < 18; i++)
			{
				var ball:Balls = new Balls()
				if (i == 0)
					target = ball
				ball.border = true;
				box.getLayout().append(ball);
				
			}
			box.border = true;
			/* box.render(this);*/
			
			panel.width = 200;
			panel.height = 200;
			panel.render(this);
			
			
			panel.border = true;
			
			/*
			   var scrollPanel:ScrollPanel = new ScrollPanel();
			   //  var  scrollPanel:Box = new Box();
			   scrollPanel.x = 620;
			   scrollPanel.y = 100
			   scrollPanel.width = 300;
			   scrollPanel.height = 300;
			   scrollPanel.source = box;
			   scrollPanel.scrollDrag = true;
			   scrollPanel.render(this);
			 */
			
			setTimeout(function():void
				{
					
					
						for (var i:int = 0; i < 16; i++)
						{
							var ball:Balls = new Balls();						 
							ball.border = true;
							box.getLayout().append(ball);
						}
					panel.sourceUpdate();
					
				//	box.getLayout().margin = new LayoutMargin(5, 5, 5, 50);
				//layout.updateAlign(null,FlowLayoutAlign.HAlign_LEFT);
				//layout.updateAlign(FlowLayoutAlign.VAlign_CENTER,FlowLayoutAlign.HAlign_CENTER);
				
				//layout.updateAlign( BoxLayoutAlign.X_AXIS);
				/*	layout.remove(target);
				   layout.updateAlign("center");
				
				   box.width = 700
				 layout.updateAlign();*/
				//box.getLayout().remove(target);
				}, 33000)
		
			//box.sourceUpdate();
			//flowLayout.updateAlign();
		
			//trace(box.height)
			//box.height =210
			//flowLayout.remove(target);}
	
	}
	}
}